// hyb_yl/userLife/pages/position/position.js
var bmap = require('../../../../utils/bmap-wx.min.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showUserAddr: [],
    moreAddr: !1,
    manualCity: "",
    text: "",
    searchval:'',
    baidukey:''
  },
  searchMerge:function(e){
    var that = this
    var searchval = e.detail.value
    that.setData({
      searchval:searchval
    })
    if(searchval.length == 0){
      that.setData({
        searchMerge:[]
      })
    }else{
      var baidukey = that.data.baidukey
      var BMap = new bmap.BMapWX({ 
        ak: baidukey 
      }); 
      var fail = function(data) { 
        console.log(data) 
      }; 
      var success = function(data) { 
          that.setData({ 
            searchMerge: data.result
          }); 
      } 
    }
    BMap.suggestion({ 
      query: e.detail.value, 
      region: that.data.manualCity, 
      city_limit: true, 
      fail: fail, 
      success: success 
  }); 
  },
  
  clear: function() {
    this.setData({
      searchMerge: [],
      searchval: ""
    })
  },
  
  goBack: function(e) {
    console.log(e)
    var that = this
    var item = e.currentTarget.dataset.position
    // that.setData({
    //   manualCity:item.name
    // })
    wx.navigateBack({
      delta:1
    })
    wx.setStorageSync('hospital', item.name)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var city = wx.getStorageSync('city')
    
    var baidukey = wx.getStorageSync('baidukey')
    that.setData({
      manualCity:city,
      baidukey:baidukey
    })
    console.log(that.data.baidukey)
    // console.log(app)
    // console.log(t)
    // e = t.miniUserId || null,
    // o = t.token || null;
  // app.util.request({
  //   'url': 'entry/wxapp/Base',
  //   success: function(res) {
  //     console.log(res)
  //     // a.setData({
  //     //   ak: res.data.data.baidukey,
  //     //   base: res.data.data
  //     // })
  //   },
  // })
  // wx.setNavigationBarColor({
  //     frontColor: wx.getStorageSync("color"),
  //     backgroundColor: wx.getStorageSync("bcolor"),
  // })
  // // e && o && a.userAddress(e, o),
  //   wx.getLocation({
  //     type: "wgs84",
  //     success: function(t) {
  //       console.log("tttttttt")
  //       console.log(t)
  //       a.getCommunity(t.longitude, t.latitude);
  //     }
  //   })

  //   s.hasDstAddrs ? a.setData({
  //     hasDstAddrs: s.hasDstAddrs,
  //     manualCity: t.manualCity
  //   }) : a.setData({
  //     hasDstAddrs: !1
  //   })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})